//
//  LSZQrCodeViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/6/6.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZQrCodeViewController.h"

@interface LSZQrCodeViewController ()<UINavigationControllerDelegate>
@property(nonatomic,strong) NSString * qrCodeString;
@property(nonatomic,strong) UIImageView * imageViewQrCode;
@end

@implementation LSZQrCodeViewController
 -(void)getImageViewShare
{
    [LSZRequestData getPictureOfTheRecipient:^(BOOL isOK, NSString * str, NSDictionary * diction) {
        if (isOK == YES) {
            NSDictionary * dicData = diction[@"data"];
            if ([[dicData allKeys] containsObject:@"qr"]) {
                self.qrCodeString = dicData[@"qr"];
                [self.imageViewQrCode sd_setImageWithURL:[NSURL URLWithString:self.qrCodeString] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            }
        }else{
            [self setStringWarning:str];
        }
    }];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;

//    self.title = @"二维码邀请";
    [self getImageViewShare];
    UIImageView * imageViewTop = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, NAVIGATION_BAR_HEIGHT)];
    imageViewTop.image = [UIImage imageNamed:@"二维码分享头"];
    [self.view addSubview:imageViewTop];

    UIImageView * imageViewBack = [[UIImageView alloc]initWithFrame:CGRectMake(0,NAVIGATION_BAR_HEIGHT, ScreenWidth, ScreenHeight-NAVIGATION_BAR_HEIGHT)];
    imageViewBack.image = [UIImage imageNamed:@"二维码分享"];
    imageViewBack.userInteractionEnabled = YES;
    [self.view addSubview:imageViewBack];


    UIButton * butReturn = [[UIButton alloc]init];
    [butReturn setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [butReturn addTarget:self action:@selector(clickButReturn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:butReturn];
    //    butReturn.backgroundColor = [UIColor yellowColor];

    UILabel * labelTitleString = [[UILabel alloc]init];
    labelTitleString.textColor = [UIColor whiteColor];
    labelTitleString.text = @"二维码邀请";
    labelTitleString.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:labelTitleString];


    UILabel * labelTitle = [[UILabel alloc]init];
    labelTitle.textColor =  redUIColor;
    labelTitle.text = @"九酷福音送给弟兄姊妹最好的礼物!";
    labelTitle.textAlignment = NSTextAlignmentCenter;
    [imageViewBack addSubview:labelTitle];

    self.imageViewQrCode = [[UIImageView alloc]init];
    [self.imageViewQrCode sd_setImageWithURL:[NSURL URLWithString:self.qrCodeString] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    [imageViewBack addSubview:self.imageViewQrCode];

    UILabel * labelExplain = [[UILabel alloc]init];
    labelExplain.textAlignment = NSTextAlignmentCenter;
    labelExplain.textColor = redUIColor;
    labelExplain.text = @"分享到以下平台让更多人接受主的福音";
    [imageViewBack addSubview:labelExplain];

    UIButton * butWeChat = [[UIButton alloc]init];
//    butWeChat.backgroundColor = [UIColor yellowColor];
    [imageViewBack addSubview:butWeChat];
    UIImageView * imageViewWeChat = [[UIImageView alloc]init];
    imageViewWeChat.image = [UIImage imageNamed:@"二维码_微信"];
    [butWeChat addSubview:imageViewWeChat];

    UILabel * labelWeChat = [[UILabel alloc]init];
    labelWeChat.textColor = [UIColor whiteColor];
    labelWeChat.textAlignment = NSTextAlignmentCenter;
    labelWeChat.text = @"微信";
    [butWeChat addSubview:labelWeChat];
    //微信分享
    [butWeChat addTarget:self action:@selector(clickButWeChat) forControlEvents:UIControlEventTouchUpInside];
    [imageViewWeChat tapGesture:^(UIGestureRecognizer *ges) {
        [self clickButWeChat];
    }];
    [labelWeChat tapGesture:^(UIGestureRecognizer *ges) {
        [self clickButWeChat];
    }];

    UIButton * butCircleFriends = [[UIButton alloc]init];
//    butCircleFriends.backgroundColor = [UIColor redColor];
    [imageViewBack addSubview:butCircleFriends];

    UIImageView * imageViewCircleFriends = [[UIImageView alloc]init];
    imageViewCircleFriends.image = [UIImage imageNamed:@"二维码_朋友圈"];
    [butCircleFriends addSubview:imageViewCircleFriends];

    UILabel * labelCircleFriends = [[UILabel alloc]init];
    labelCircleFriends.textColor = [UIColor whiteColor];
    labelCircleFriends.textAlignment = NSTextAlignmentCenter;
    labelCircleFriends.text = @"朋友圈";
    [butCircleFriends addSubview:labelCircleFriends];
    //朋友圈分享
    [butCircleFriends addTarget:self action:@selector(clickButCircleFriends) forControlEvents:UIControlEventTouchUpInside];
    [imageViewCircleFriends tapGesture:^(UIGestureRecognizer *ges) {
        [self clickButCircleFriends];
    }];
    [labelCircleFriends tapGesture:^(UIGestureRecognizer *ges) {
        [self clickButCircleFriends];
    }];

    UIButton * butQQ = [[UIButton alloc]init];
//    butQQ.backgroundColor = [UIColor yellowColor];
    [imageViewBack addSubview:butQQ];
    UIImageView * imageViewQQ = [[UIImageView alloc]init];
    imageViewQQ.image = [UIImage imageNamed:@"二维码_QQ"];
    [butQQ addSubview:imageViewQQ];

    UILabel * labelQQ = [[UILabel alloc]init];
    labelQQ.textColor = [UIColor whiteColor];
    labelQQ.textAlignment = NSTextAlignmentCenter;
    labelQQ.text = @"QQ";
    [butQQ addSubview:labelQQ];
    //QQ分享
    [butQQ addTarget:self action:@selector(clickButQQ) forControlEvents:UIControlEventTouchUpInside];
    [imageViewQQ tapGesture:^(UIGestureRecognizer *ges) {
        [self clickButQQ];
    }];
    [labelQQ tapGesture:^(UIGestureRecognizer *ges) {
        [self clickButQQ];
    }];

    CGFloat heightTotle = imageViewBack.frame.size.height;
    CGFloat lowWidth = (ScreenWidth-heightTotle/595*195)/182;

    if (ScreenWidth == 320) {
        //5
        labelTitle.font = FONT_(13.5);
        labelExplain.font = FONT_(13.5);
        labelWeChat.font = FONT_(15);
        labelCircleFriends.font = FONT_(15);
        labelQQ.font = FONT_(15);

//        labelTitle.frame = CGRectMake(0,heightTotle/595*38,ScreenWidth,heightTotle/595*20);
//        imageViewQrCode.frame = CGRectMake((ScreenWidth-heightTotle/595*155)/2, CGRectGetMaxY(labelTitle.frame)+heightTotle/595*10, heightTotle/595*155,heightTotle/595*155);
//        labelExplain.frame = CGRectMake(0,heightTotle/595*407,ScreenWidth,heightTotle/595*20);
//
//        butWeChat.frame = CGRectMake(lowWidth*58,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
//        imageViewWeChat.frame = CGRectMake(heightTotle/595*10, heightTotle/595*10, butWeChat.frame.size.width-heightTotle/595*20,butWeChat.frame.size.width-heightTotle/595*20);
//        labelWeChat.frame = CGRectMake(0, heightTotle/595*9, butWeChat.frame.size.width, heightTotle/595*17);
//
//        butCircleFriends.frame = CGRectMake(CGRectGetMaxX(butWeChat.frame)+lowWidth*33,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
//        imageViewCircleFriends.frame = CGRectMake(heightTotle/595*10, heightTotle/595*10, butWeChat.frame.size.width-heightTotle/595*20,butWeChat.frame.size.width-heightTotle/595*20);
//        labelCircleFriends.frame = CGRectMake(0, heightTotle/595*9, butWeChat.frame.size.width, heightTotle/595*17);
//
//        butQQ.frame = CGRectMake(CGRectGetMaxX(butCircleFriends.frame)+lowWidth*34,CGRectGetMaxY(labelExplain.frame)+20, heightTotle/595*65,heightTotle/595*90);
//        imageViewQQ.frame = CGRectMake(heightTotle/595*10, heightTotle/595*10, butWeChat.frame.size.width-heightTotle/595*20,butWeChat.frame.size.width-heightTotle/595*20);
//        labelQQ.frame = CGRectMake(0, heightTotle/595*9, butWeChat.frame.size.width, heightTotle/595*17);

    }else if(ScreenWidth == 375){
        // 6 7
        labelTitle.font = FONT_(14);
        labelExplain.font = FONT_(14);
        labelWeChat.font = FONT_(15.5);
        labelCircleFriends.font = FONT_(15.5);
        labelQQ.font = FONT_(15.5);

//        labelTitle.frame = CGRectMake(0,heightTotle/595*38,ScreenWidth,heightTotle/595*20);
//        imageViewQrCode.frame = CGRectMake((ScreenWidth-heightTotle/595*155)/2, CGRectGetMaxY(labelTitle.frame)+heightTotle/595*10, heightTotle/595*155,heightTotle/595*155);
//        labelExplain.frame = CGRectMake(0,heightTotle/595*407,ScreenWidth,heightTotle/595*20);
//
//        butWeChat.frame = CGRectMake(lowWidth*58,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
//        butCircleFriends.frame = CGRectMake(CGRectGetMaxX(butWeChat.frame)+lowWidth*33,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
//        butQQ.frame = CGRectMake(CGRectGetMaxX(butCircleFriends.frame)+lowWidth*34,CGRectGetMaxY(labelExplain.frame)+20, heightTotle/595*65,heightTotle/595*90);
    }else {
        //plus
        labelTitle.font = FONT_(14.5);
        labelExplain.font = FONT_(14);
        labelWeChat.font = FONT_(16);
        labelCircleFriends.font = FONT_(16);
        labelQQ.font = FONT_(16);

//        labelTitle.frame = CGRectMake(0,heightTotle/595*38,ScreenWidth,heightTotle/595*20);
//        imageViewQrCode.frame = CGRectMake((ScreenWidth-heightTotle/595*155)/2, CGRectGetMaxY(labelTitle.frame)+heightTotle/595*10, heightTotle/595*155,heightTotle/595*155);
//        labelExplain.frame = CGRectMake(0,heightTotle/595*407,ScreenWidth,heightTotle/595*20);
//
//        butWeChat.frame = CGRectMake(lowWidth*58,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
//        butCircleFriends.frame = CGRectMake(CGRectGetMaxX(butWeChat.frame)+lowWidth*33,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
//        butQQ.frame = CGRectMake(CGRectGetMaxX(butCircleFriends.frame)+lowWidth*34,CGRectGetMaxY(labelExplain.frame)+20, heightTotle/595*65,heightTotle/595*90);

    }

    labelTitle.frame = CGRectMake(0,heightTotle/595*38,ScreenWidth,heightTotle/595*20);
    self.imageViewQrCode.frame = CGRectMake((ScreenWidth-heightTotle/595*155)/2, CGRectGetMaxY(labelTitle.frame)+heightTotle/595*10, heightTotle/595*155,heightTotle/595*155);
    butReturn.frame = CGRectMake(0, STATUS_BAR_HEIGHT, 50, NAVIGATION_BAR_HEIGHT-STATUS_BAR_HEIGHT);
    labelTitleString.frame = CGRectMake(CGRectGetMaxX(butReturn.frame), STATUS_BAR_HEIGHT, ScreenWidth-CGRectGetMaxX(butReturn.frame)*2, NAVIGATION_BAR_HEIGHT-STATUS_BAR_HEIGHT);
    
    labelExplain.frame = CGRectMake(0,heightTotle/595*407,ScreenWidth,heightTotle/595*20);

    butWeChat.frame = CGRectMake(lowWidth*58,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
    imageViewWeChat.frame = CGRectMake(heightTotle/595*10, heightTotle/595*10, butWeChat.frame.size.width-heightTotle/595*20,butWeChat.frame.size.width-heightTotle/595*20);
    labelWeChat.frame = CGRectMake(0, heightTotle/595*9+CGRectGetMaxY(imageViewWeChat.frame), butWeChat.frame.size.width, heightTotle/595*17);

    butCircleFriends.frame = CGRectMake(CGRectGetMaxX(butWeChat.frame)+lowWidth*33,CGRectGetMaxY(labelExplain.frame)+20,heightTotle/595*65,heightTotle/595*90);
    imageViewCircleFriends.frame = CGRectMake(heightTotle/595*10, heightTotle/595*10, butWeChat.frame.size.width-heightTotle/595*20,butWeChat.frame.size.width-heightTotle/595*20);
    labelCircleFriends.frame = CGRectMake(0, heightTotle/595*9+CGRectGetMaxY(imageViewCircleFriends.frame), butWeChat.frame.size.width, heightTotle/595*17);

    butQQ.frame = CGRectMake(CGRectGetMaxX(butCircleFriends.frame)+lowWidth*34,CGRectGetMaxY(labelExplain.frame)+20, heightTotle/595*65,heightTotle/595*90);
    imageViewQQ.frame = CGRectMake(heightTotle/595*10, heightTotle/595*10, butWeChat.frame.size.width-heightTotle/595*20,butWeChat.frame.size.width-heightTotle/595*20);
    labelQQ.frame = CGRectMake(0, heightTotle/595*9+CGRectGetMaxY(imageViewQQ.frame), butWeChat.frame.size.width, heightTotle/595*17);


}
#pragma mark - 微信分享
-(void)clickButWeChat
{
    [self ZKKShareViewDidSelecteBtnWithBtnText:@"分享微信"];
}
#pragma mark - 朋友圈分享
-(void)clickButCircleFriends
{
    [self ZKKShareViewDidSelecteBtnWithBtnText:@"分享朋友圈"];
}
#pragma mark -QQ分享
-(void)clickButQQ
{
    [self ZKKShareViewDidSelecteBtnWithBtnText:@"分享QQ"];
}
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
-(void)clickButReturn
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
